$(function() {
	new Vue({
		el: '#auditHistoryApp',
		data: {
			currentPage: 100,
			fullscreenLoading: false,
			searchdeliver: "",
			dialogFormVisible: false,
			tableData: [],
			refoundHistory: [],
		},
		created: function() {
			parent.vueData.$data.hreHtml = "../auditHistoryList/index.html";
			parent.vueData.activeIndex = "5";
			parent.vueData.getLeftNav("5")
			parent.vueData.$data.categoryIndex = 4
			this.getRejectOrderList()
		},
		methods: {

			getRejectOrderList() {
				this.fullscreenLoading = true;
				axios({
					url: POSTURL.selAdminRecord,
					method: 'post',
					data: {
						data:""
					}
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						this.tableData = response.data.result;
						console.log(this.tableData);
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})
			},
			//查看协商历史
			handleHistory(orderInfo) {
				this.refoundHistory = [];
				this.fullscreenLoading = true;
				axios({
					url: POSTURL.awaitPayment,
					method: 'post',
					data: {}
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						for (let model of response.data.result) {
							if (model.isShop === "-1") {
								model.noteStr = model.refundNode
							} else {
								let headerStr = "";
								if (model.refoundGood === 1) {
									headerStr = "发起了退货退款申请, ";
								} else {
									headerStr = "发起了仅退款申请，";
								}
								let goodStatus = "";
								if (model.state < 4) {
									goodStatus = "货物状态：未发货，";
								} else {
									goodStatus = "货物状态：已发货，";
								}
								let reasonStr = "";
								if (!stringEmpty(model.refundReason)) {
									reasonStr = "原因：" + model.refundReason + ","
								}
								let node = "";
								if (!stringEmpty(model.refundNode)) {
									node = "备注：" + model.refundNode + ","
								}
								model.noteStr = headerStr + goodStatus + reasonStr + node + "金额：" + model.refundMoney + "元";
							}
							this.refoundHistory.push(model);

						}
						this.dialogFormVisible = true;
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})

			},
			//同意
			handleAgree(orderInfo) {
				this.handelOrderInfo(orderInfo, "0");
			},
			//拒绝
			handleRefuse(orderInfo) {
				this.handelOrderInfo(orderInfo, "1");
			},
			//处理请求
			handelOrderInfo(orderInfo, status) {
				this.fullscreenLoading = true;
				axios({
					url: POSTURL.auditAdminIntervention,
					method: 'post',
					data: {
						id: orderInfo.id,
						data: status
					}
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						this.tableData.pop(orderInfo);
						this.$message({
							showClose: true,
							message: response.data.message,
							type: 'success'
						});
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})
			},
			//强制退款给用户
			handleForceRefound(orderInfo) {
				this.handelForceRequest(orderInfo, "0")
			},
			//强制退款给商家
			handleForceRefoundShop(orderInfo) {
				this.handelForceRequest(orderInfo, "1")
			},
			//请求
			handelForceRequest(orderInfo, status) {
				this.fullscreenLoading = true;
				let param = {
					id: orderInfo.id,
					data: status
				}
				axios({
					url: POSTURL.mandatoryIntervention,
					method: 'post',
					data: param
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						this.tableData.pop(orderInfo);
						this.$message({
							showClose: true,
							message: response.data.message,
							type: 'success'
						});
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})
			}
		}
	})
})
